﻿CREATE TABLE [dbo].[OrderBase] (
    [Id]                 UNIQUEIDENTIFIER DEFAULT (newid()) NOT NULL,
    [SerialNo]           NVARCHAR (32)    NOT NULL,
    [HappenDate]         DATETIME         NULL,
    [IsDraft]            BIT              DEFAULT ((1)) NOT NULL,
    [CreatedTime]        DATETIME         NULL,
    [LastModifiedTime]   DATETIME         NOT NULL,
    [IsSubmited]         BIT              DEFAULT ((0)) NULL,
    [SubmitedTime]       DATETIME         NULL,
    [IsAudited]          BIT              DEFAULT ((0)) NULL,
    [AuditedTime]        DATETIME         NULL,
    [IsApproved]         BIT              DEFAULT ((0)) NULL,
    [ApprovedTime]       DATETIME         NULL,
    [IsInvalid]          BIT              DEFAULT ((0)) NULL,
    [InvalidTime]        DATETIME         NOT NULL,
    [CreateUserID]       UNIQUEIDENTIFIER NOT NULL,
    [LastModifiedUserID] UNIQUEIDENTIFIER NOT NULL,
    [SubmitedUserID]     UNIQUEIDENTIFIER NOT NULL,
    [AuditedUserID]      UNIQUEIDENTIFIER NOT NULL,
    [ApprovedUserID]     UNIQUEIDENTIFIER NOT NULL,
    [InvalidUserID]      UNIQUEIDENTIFIER NOT NULL,
    PRIMARY KEY CLUSTERED ([Id] ASC),
    CONSTRAINT [FKD0CFD82711E65B0E] FOREIGN KEY ([LastModifiedUserID]) REFERENCES [dbo].[UserProfile] ([ID]),
    CONSTRAINT [FKD0CFD82766918D98] FOREIGN KEY ([SubmitedUserID]) REFERENCES [dbo].[UserProfile] ([ID]),
    CONSTRAINT [FKD0CFD827BAC31548] FOREIGN KEY ([InvalidUserID]) REFERENCES [dbo].[UserProfile] ([ID]),
    CONSTRAINT [FKD0CFD827C5F8028D] FOREIGN KEY ([CreateUserID]) REFERENCES [dbo].[UserProfile] ([ID]),
    CONSTRAINT [FKD0CFD827CB3BF2C6] FOREIGN KEY ([ApprovedUserID]) REFERENCES [dbo].[UserProfile] ([ID]),
    CONSTRAINT [FKD0CFD827E95B4E3F] FOREIGN KEY ([AuditedUserID]) REFERENCES [dbo].[UserProfile] ([ID])
);

